//
//  XLReChagerTableViewCell.m
//  XiangLove
//
//  Created by 宋振 on 2018/8/3.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLReChagerTableViewCell.h"
#import "XLPersonCenterTool.h"

@interface XLReChagerTableViewCell ()

//支付标志
@property (nonatomic, strong) UIImageView *  payTypeImage;

//充值金豆
@property (nonatomic, strong) UILabel *  consumeBeanLbl;

//金额
@property (nonatomic, strong) UILabel *  consemeMoneyLbl;

//订单号
@property (nonatomic, strong) UILabel *  orderNumber;

//创建时间
@property (nonatomic, strong) UILabel *  creatTimeLbl;

@end

@implementation XLReChagerTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        //绘制界面显示
        [self setCustomeView];
        
    }
    
    return self;
}

#pragma mark    - - -Layout UI- - -

/**
 绘制界面显示
 */
- (void)setCustomeView
{
    //支付类型标志
    self.payTypeImage = [[UIImageView alloc] init];
    
    //设置一个默认
    self.payTypeImage.image = [UIImage imageNamed:@"message_list_icon_zhi_n"];
    [self.contentView addSubview:self.payTypeImage];
    
    [self.payTypeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.left.equalTo(self.contentView.mas_left).offset(kScale(15));
        make.size.mas_equalTo(CGSizeMake(48, 48));
    }];
    
    
    //充值金豆
    self.consumeBeanLbl = [[UILabel alloc] init];
    
    self.consumeBeanLbl.attributedText = [self setAttributeText:@"" textColor:RGB(17, 17, 17) kernName:2 FontName:KFontNamePFMedium fontSize:17];
    [self setDecoratedForLabel:self.consumeBeanLbl alignment:(NSTextAlignmentLeft)];
    [self.contentView addSubview:self.consumeBeanLbl];
    
    [self.consumeBeanLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.payTypeImage.mas_top);
        make.left.equalTo(self.payTypeImage.mas_right).offset(kScale(10));
        make.width.lessThanOrEqualTo(@(kScale(181)));
        make.height.mas_equalTo(24);
    }];
    
    //充值金额
    self.consemeMoneyLbl = [[UILabel alloc] init];
    
    self.consemeMoneyLbl.attributedText = [self setAttributeText:@"" textColor:RGB(255, 187, 1) kernName:0 FontName:KFontNamePFMedium fontSize:15];
    
    [self setDecoratedForLabel:self.consemeMoneyLbl alignment:(NSTextAlignmentRight)];
    [self.contentView addSubview:self.consemeMoneyLbl];
    
    [self.consemeMoneyLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.consumeBeanLbl.mas_centerY);
        make.right.equalTo(self.contentView.mas_right).offset(-kScale(15));
        make.height.mas_equalTo(21);
    }];
    
    //订单号
    self.orderNumber = [[UILabel alloc] init];
    self.orderNumber.attributedText = [self setAttributeText:@"" textColor:RGB(102, 102, 102) kernName:1 FontName:KFontNamePFMedium fontSize:12];
    [self setDecoratedForLabel:self.orderNumber alignment:(NSTextAlignmentLeft)];
    
    [self.contentView addSubview:self.orderNumber];
    
    [self.orderNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.consumeBeanLbl.mas_left);
        make.bottom.equalTo(self.payTypeImage.mas_bottom);
        make.width.lessThanOrEqualTo(@(kScale(196)));
    }];
    
    //创建时间
    self.creatTimeLbl = [[UILabel alloc] init];
    
    self.creatTimeLbl.attributedText = [self setAttributeText:@"" textColor:RGB(153, 153, 153) kernName:1 FontName:KFontNamePFMedium fontSize:12];
    
    [self setDecoratedForLabel:self.creatTimeLbl alignment:(NSTextAlignmentLeft)];
    [self.contentView addSubview:self.creatTimeLbl];
    
    [self.creatTimeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.orderNumber.mas_centerY);
        make.right.equalTo(self.contentView.mas_right).offset(-kScale(15));
        make.height.mas_equalTo(17);
    }];
    
    //分割线
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = RGB(238, 238, 238);
    [self.contentView addSubview:line];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.consumeBeanLbl.mas_left).offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-0.5);
        make.right.equalTo(self.contentView.mas_right).offset(-91);
//        make.width.mas_equalTo(296);
        make.height.mas_equalTo(0.5);
    }];
}

#pragma mark    - - - 设置数据 - - -

- (void)setModel:(XLReChagerModel *)model
{
    _model = model;
    
    if (_model) {
        
        //设置图片
        UIImage *img = nil;
        
        
        if ([model.PayType isEqualToString:@"4"] || [model.PayType isEqualToString:@"2"])
        {
            //支付宝
            img = [[UIImage imageNamed:@"message_list_icon_zhi_n"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
            
        }else if ([model.PayType isEqualToString:@"5"] || [model.PayType isEqualToString:@"1"])
        {
            //微信
            img = [[UIImage imageNamed:@"message_list_icon_weixin_n"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
            
        }else if ([model.PayType isEqualToString:@"6"])
        {
            //苹果
            img = [[UIImage imageNamed:@""] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
            
        }
        
        self.payTypeImage.image = img;
        
        //金豆
        NSString *beans = [NSString stringWithFormat:@"充值%.lf金豆",[K_DEFULT(model.Money) floatValue]*10];
        
        
        
        self.consumeBeanLbl.attributedText = [self setAttributeText:K_DEFULT(model.Remarks) textColor:RGB(17, 17, 17) kernName:2 FontName:KFontNamePFMedium fontSize:17];;
        
        //金额
        NSString *money = [NSString stringWithFormat:@"%@元",K_DEFULT(model.Money)];
        
        self.consemeMoneyLbl.attributedText = [self setAttributeText:money textColor:RGB(255, 187, 1) kernName:0 FontName:KFontNamePFMedium fontSize:15];
        
        //订单号
        
        NSString *order = [NSString stringWithFormat:@"订单号：%@",K_DEFULT(model.OrderNo)];
        
        self.orderNumber.attributedText = [self setAttributeText:order textColor:RGB(102, 102, 102) kernName:1 FontName:KFontNamePFMedium fontSize:12];
        
        //创建时间
        
        self.creatTimeLbl.attributedText = [self setAttributeText:K_DEFULT(model.CreateTime) textColor:RGB(153, 153, 153) kernName:1 FontName:KFontNamePFMedium fontSize:12];
        
        
    }
}


#pragma mark    - - -修饰控件方法- - -

//设置文字: 文字，颜色，字间距，字体字号
- (NSMutableAttributedString *)setAttributeText:(NSString *)text textColor:(UIColor *)color kernName:(CGFloat)kern FontName:(NSString *)fontName fontSize:(CGFloat)fontSize
{
    NSDictionary *dic;
    
    dic = @{NSKernAttributeName:@(kern),
            NSFontAttributeName:[UIFont fontWithName:fontName size:fontSize],
            NSForegroundColorAttributeName:color
            };
    
    
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:dic];
    
    return attribute;
}

//设置label
- (void)setDecoratedForLabel:(UILabel *)label alignment:(NSTextAlignment)alignment
{
    label.textAlignment = alignment;
}




@end
